package test.through.tree;
import java.math.BigDecimal;

import hyl.base.flow.chart.CNode;
import hyl.base.flow.chart.CWorkOrd;
import hyl.base.flow.chart.INode;
import hyl.base.flow.chart.IWorkOrd;
import hyl.base.flow.chart.IWorker;
import hyl.core.MyFun;

/**
 * 
 * <p>className: TreeRwdDP  </p>
 * <p>Description: 碰对奖  左右区达到规定的比例时，包含点碰或量碰，可获得奖金。
 * 支持比例为  1:1,  1:2,  1:3等。  </p>
 * @author:  zdy
 * @date: 2018年9月19日 上午9:56:05  
 * @copyright: 2018 da you zou Inc. All rights reserved.
 */
public class CworkTree2DRwdDP implements IWorker   {


	private final String CONSUME = "DPJ"; //对应数据库.表.字段
	private final String NAME = "对碰奖";//定义奖金名称
	private final String PP1= "DP1:3" ;//定义扩展属性名称
	private final BigDecimal y = BigDecimal.valueOf(0.05);
	private final int rate = 3;// 左边:右边=1:3 	

	private BigDecimal x = BigDecimal.valueOf(1000);

	

	private void setRwd(CNode p,int ln,int rn) {
		Creward r = new Creward();
		r.setWho(p.getId());
		r.setHowmuch(x.toPlainString());
		r.setSubject(this.NAME);
		r.setRemark("因为 (左区:右区=1:3="+ln+":"+rn+")");
		r.setTime(MyFun.getNow());
		//p.setEvent(r.getSort(), r);
	}

	@Override
	public Object run(INode 当前节点,IWorkOrd 待加工对象,Object ...其他参数) throws Exception {
		CNode parent =(CNode) 当前节点.getParent();
		Character state = (Character) parent.getAttr(PP1);
		if (state == null||state=='0') {
			CNode left = (CNode)parent.getChild("位置","L");
			CNode right = (CNode)parent.getChild("位置","R");
			int ln = (int) left.getAttr("nodes");//
			int rn = (int) right.getAttr("nodes");
			if (ln * 3 >= rn) {
				parent.putAttr(PP1, '1');//认领后为2
				setRwd(parent,ln,rn );
				return true;
			}
		}
		return false;
	}

}
